package com.jd.service.impl;

import com.gavel.database.SQLExecutor;
import com.gavel.parser.AttrTable;
import com.gavel.parser.MYMROSkuParser;
import com.gavel.parser.SkuItem;
import com.gavel.utils.HtmlLoder;
import com.gavel.utils.StringUtils;
import com.jd.service.JDIntroService;
import com.mrobuy.jdvc.dao.VCItemDao;
import com.mrobuy.jdvc.dao.VCProductInfoDao;
import com.mrobuy.jdvc.entity.VCItem;
import com.mrobuy.jdvc.entity.VCProductInfo;
import com.mrobuy.jdvc.entity.VCShelvesItem;
import com.mrobuy.jdvc.service.HtmlLodService;
import com.mrobuy.jdvc.service.VCPictureService;
import com.mrobuy.util.CodeEncoder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.MathContext;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

@Service("jdIntroService")
public class JDIntroServiceImpl implements JDIntroService {

    private static Logger LOG = LoggerFactory.getLogger(JDIntroService.class);

    @Autowired
    private VCProductInfoDao vcProductInfoDao;

    @Autowired
    private VCItemDao vcItemDao;

    @Autowired
    private HtmlLodService htmlLodService;

    @Autowired
    private VCPictureService vcPictureService;

    @Override
    public String buildPCIntroHtml(String _wareId) {

        VCProductInfo vcProductInfo = loadVCProductInfo(_wareId);
        if ( vcProductInfo==null ) {
            LOG.info("[WareId: " + _wareId + "]VCProductInfo not found.");
            return null;
        }

        if ( vcProductInfo.getIsGaea()==1 ) {
            // 盖亚

        } else {
            // 非盖亚
            buildPCIntroHtml(vcProductInfo);
        }



        return null;
    }

    /**
     *  非盖亚 PC端商品详情
     * @param vcProductInfo
     */
    private String buildPCIntroHtml(VCProductInfo vcProductInfo) {

        List<VCItem> vcItems = vcItemDao.loadByWareId(vcProductInfo.getWareId());
        if ( vcItems==null ) {
            return null;
        }

        if ( vcItems.size() > 1 ) {
            LOG.info("[WareId: {}]SKU数量: {}", vcProductInfo.getWareId(), vcItems.size());
            return null;
        }

        VCItem vcItem = vcItems.get(0);
        String code = CodeEncoder.decoder( vcItem.getItemNum());

        String url = String.format("https://www.mymro.cn/u-%s.html", code);
        String html = htmlLodService.load(url);
        MYMROSkuParser skuParser = new MYMROSkuParser();
        SkuItem skuItem = skuParser.parser(url, html);
        if ( skuItem==null ) {
            System.out.println("[" + code + ": " + vcItem.getSkuName() + "]SKU信息解析失败.");
            return "";
        }


        return "";
    }

    /**
     *  非盖亚 移动版商品详情
     * @param vcProductInfo
     */
    private String buildMobileIntroHtml(VCProductInfo vcProductInfo) {

        return "";
    }

    @Override
    public String buildMobileIntroHtml(String _wareId) {

        VCProductInfo vcProductInfo = loadVCProductInfo(_wareId);
        if ( vcProductInfo==null ) {
            LOG.info("[WareId: " + _wareId + "]VCProductInfo not found.");
            return null;
        }

        if ( vcProductInfo.getIsGaea()==1 ) {
            // 盖亚

        } else {
            // 非盖亚
        }

        return null;
    }

    @Override
    public String buildPCIntroHtml(List<VCShelvesItem> items) {

        if ( items==null || items.size()==0 ) {
            return "";
        }

        List<String> newItems = items.stream().map(e -> e.getSkucode() ).collect(Collectors.toList());

        if ( items.size()==1 ) {
            return buildPCSingleSkuIntro(newItems.get(0));
        }

        return buildPCMultiSkuIntro(newItems);
    }

    @Override
    public String buildPCIntroHtml2(List<VCItem> items) {

        if ( items==null || items.size()==0 ) {
            return "";
        }

        List<String> newItems = items.stream().map(e -> CodeEncoder.decoder(e.getItemNum()) ).collect(Collectors.toList());

        String retStr;
        if ( items.size()==1 ) {
            retStr = buildPCSingleSkuIntro(newItems.get(0));
        }else {
            retStr = buildPCMultiSkuIntro(newItems);
        }
        retStr = StringUtils.replaceIgnoreCase(retStr, "固安捷[\\w\\W]+公司", "帷易胜(江苏)工业品有限公司");
        return retStr;
    }
    /**
     * 多产品详情页
     * @param items
     * @return
     */
    private String buildPCMultiSkuIntro(List<String> items) {

        if ( items==null || items.size()==0 ) {
            return "";
        }

        SkuItem skuItem = null;
        AttrTable attrTable = null;

        MYMROSkuParser skuParser = new MYMROSkuParser();

        for (String item : items) {
            System.out.println("))))))))"+item);
            String url = String.format("https://www.mymro.cn/u-%s.html", item);
            String html = htmlLodService.load(url);

            System.out.println(url+"))))))))"+html);
            skuItem = skuParser.parser(url, html);
            if ( skuItem!=null ) {
                attrTable = skuParser.attrTable(html);
                break;
            }
        }

        if ( skuItem==null ) {
            return "";
        }

        String intro = skuItem.getIntro();
        if ( StringUtils.isNotBlank(skuItem.getBrand()) ) {
            intro = StringUtils.replaceIgnoreCase(intro, skuItem.getBrand(), "");
        }
        if ( StringUtils.isNotBlank(skuItem.getBrandEn()) ) {
            intro = StringUtils.replaceIgnoreCase(intro, skuItem.getBrandEn(), "");
        }
        int height = 100;
        String[] lines = intro.split("<br>");
        if ( lines!=null && lines.length > 3  ) {
            height = 60 + lines.length*20;
        }


        StringBuilder tableBuilder = new StringBuilder();
        if ( attrTable.getHeaders()!=null && attrTable.getHeaders().size() > 0 ) {

            Set<String> codeSet = items.stream().collect(Collectors.toSet());

            tableBuilder.append("<table>\n");
            tableBuilder.append(
                    "           <thead class=\"thead-dark\">\n" +
                    "                       <tr>\n" +
                    "                                    <th class=\"productcode\">型号</th>\n");
            for (String header : attrTable.getHeaders()) {
                tableBuilder.append("                    <th>").append(header).append("</th>\n");
            }
            tableBuilder.append(
                    "                       </tr>\n" +
                    "            </thead>\n" +
                    "            <tbody>\n");

            for (Map<String, String> record : attrTable.getDatas()) {
               String code = record.remove("订货号");
               if ( StringUtils.isBlank(code) ) {
                   continue;
               }

               if ( !codeSet.contains(code.trim()) ) {
                    continue;
               }

                String model = record.remove("制造商型号");
                tableBuilder.append("   <tr>\n" +
                        "                    <td class=\"productcode\">" + model + "</td>\n");
                for (String header : attrTable.getHeaders()) {
                    tableBuilder.append("    <td>" + record.get(header)  + "</td>\n");
                }
                tableBuilder.append("   </tr>\n");
            }
            tableBuilder.append("   </tbody>\n" +
                    "            </table>");
        }


        // 详情图片
        StringBuilder imageHtml = new StringBuilder();
        {
            if (  skuItem.getDetailPics()!=null ) {
                for (SkuItem.Pic pic : skuItem.getDetailPics()) {
                    try {
                        String vcUrl = vcPictureService.loadVCPicUrl(pic.getUrl(), "");
                        if (  StringUtils.isNotBlank(vcUrl) ) {
                            imageHtml.append(" <img src='" + vcUrl + "' />\n");
                            break;
                        }
                    } catch (Exception e) {

                    }
                }
            }
        }

        // 如果没有详情图片, 添加一张主图图片
        if ( imageHtml.length() == 0 ) {
            if (  skuItem.getProductPics()!=null ) {
                for (SkuItem.Pic pic : skuItem.getProductPics()) {
                    try {
                        String vcUrl = vcPictureService.loadProductVCPicUrl(pic.getUrl(), "");
                        if (  StringUtils.isNotBlank(vcUrl) ) {
                            imageHtml.append(" <img src='" + vcUrl + "' />\n");
                        }
                    } catch (Exception e) {

                    }
                }
            }
        }



        String html = "<div>\n" +
                "    <style>.ssd-module-wrap {\n" +
                "        position: relative;\n" +
                "        margin: 0 auto;\n" +
                "        width: 750px;\n" +
                "        text-align: left;\n" +
                "        background-color: #fff\n" +
                "    }\n" +
                "\n" +
                "    .ssd-module-wrap .ssd-module, .ssd-module-wrap .ssd-module-heading {\n" +
                "        width: 750px;\n" +
                "        position: relative;\n" +
                "        overflow: hidden\n" +
                "    }\n" +
                "\n" +
                "    .ssd-module-wrap .ssd-module {\n" +
                "        background-repeat: no-repeat;\n" +
                "        background-position: left top;\n" +
                "        background-size: 100% 100%\n" +
                "    }\n" +
                "\n" +
                "    .ssd-module-wrap .ssd-module-heading {\n" +
                "        background-repeat: no-repeat;\n" +
                "        background-position: left center;\n" +
                "        background-size: 100% 100%\n" +
                "    }\n" +
                "\n" +
                "    .ssd-module-wrap .ssd-module-heading .ssd-module-heading-layout {\n" +
                "        display: inline-block\n" +
                "    }\n" +
                "\n" +
                "    .ssd-module-wrap .ssd-module-heading .ssd-widget-heading {\n" +
                "        font-style: normal;\n" +
                "        font-family: microsoft yahei;\n" +
                "        line-height: 30px;\n" +
                "        text-decoration: none;\n" +
                "        letter-spacing: 0px;\n" +
                "        font-weight: normal;\n" +
                "        color: #ffffff;\n" +
                "        background-color: transparent;\n" +
                "        display: inline-block;\n" +
                "        height: 100%\n" +
                "    }\n" +
                "\n" +
                "    .ssd-module-wrap .ssd-widget-text {\n" +
                "        position: absolute;\n" +
                "        overflow: hidden\n" +
                "    }\n" +
                "\n" +
                "    .ssd-module-wrap .ssd-widget-text {\n" +
                "        line-height: 1.5;\n" +
                "        word-break: break-all\n" +
                "    }\n" +
                "\n" +
                "    .ssd-module-wrap .ssd-widget-text span {\n" +
                "        display: block;\n" +
                "        overflow: hidden;\n" +
                "        width: 100%;\n" +
                "        height: 100%;\n" +
                "        padding: 0;\n" +
                "        margin: 0;\n" +
                "        word-break: break-all;\n" +
                "        word-wrap: break-word;\n" +
                "        white-space: normal\n" +
                "    }\n" +
                "\n" +
                "    .ssd-module-wrap .title {\n" +
                "        width: 750px;\n" +
                "        background-color: transparent;\n" +
                "        background-image: url(//img30.360buyimg.com/sku/jfs/t2467/315/1479078334/2361/4757d7d6/566010f4N01f5d17a.png);\n" +
                "        height: 30px;\n" +
                "        text-align: left\n" +
                "    }\n" +
                "\n" +
                "    .ssd-module-wrap .title-ch {\n" +
                "        margin: 0 6px 0 15px;\n" +
                "        font-size: 14px\n" +
                "    }\n" +
                "\n" +
                "    .ssd-module-wrap .title-en {\n" +
                "        margin: 0 15px 0 6px;\n" +
                "        font-size: 12px\n" +
                "    }\n" +
                "\n" +
                "    .ssd-module-wrap .content {\n" +
                "        width: 750px;\n" +
                "        background-color: #F7F3F3;\n" +
                "        background-size: 100% auto;\n" +
                "        height: " + height + "px\n" +
                "    }\n" +
                "\n" +
                "    .ssd-module-wrap .content-text {\n" +
                "        z-index: 0;\n" +
                "        color: #000000;\n" +
                "        font-weight: normal;\n" +
                "        letter-spacing: 0px;\n" +
                "        text-decoration: none;\n" +
                "        font-size: 14px;\n" +
                "        line-height: 1.5;\n" +
                "        font-style: normal;\n" +
                "        background-color: transparent;\n" +
                "        top: 16px;\n" +
                "        left: 42px;\n" +
                "        font-family: microsoft yahei;\n" +
                "        min-height: 110px\n" +
                "    }\n" +
                "\n" +
                "    .ssd-module-wrap img {\n" +
                "        margin: 10px 0 0 0;\n" +
                "        width: 750px;\n" +
                "        background-size: 100% 100%;\n" +
                "        height: auto;\n" +
                "    }\n" +
                "\n" +
                "    table {\n" +
                "        border-collapse: collapse;\n" +
                "        margin: 0 auto;\n" +
                "        text-align: center;\n" +
                "    }\n" +
                "\n" +
                "    table tbody {\n" +
                "        display: block;\n" +
                "        max-height: 600px;\n" +
                "        overflow-y: scroll;\n" +
                "    }\n" +
                "\n" +
                "    table thead, tbody tr {\n" +
                "        display: table;\n" +
                "        width: 750px;\n" +
                "        table-layout: fixed;\n" +
                "    }\n" +
                "\n" +
                "    table thead {\n" +
                "        width: 750px;\n" +
                "    }\n" +
                "\n" +
                "    table td, table th {\n" +
                "        border: 1px solid #cad9ea;\n" +
                "        color: #666;\n" +
                "        height: 30px;\n" +
                "    }\n" +
                "\n" +
                "    table thead th {\n" +
                "        background-color: #e6e6e6;\n" +
                "    }\n" +
                "\n" +
                "    table tr:nth-child(odd) {\n" +
                "        background: #fff;\n" +
                "    }\n" +
                "\n" +
                "    table tr:nth-child(even) {\n" +
                "        background: #F5FAFA;\n" +
                "    }\n" +
                "\n" +
                "    .productcode {\n" +
                "        width: 200px;\n" +
                "    }\n" +
                "    </style>\n" +
                "\n" +
                "    <div class=\"ssd-module-wrap\">\n" +
                "        <div class=\"ssd-module-heading title\">\n" +
                "            <div class=\"ssd-module-heading-layout\">\n" +
                "                <span class=\"ssd-widget-heading title-ch\">产品信息</span>\n" +
                "                <span class=\"ssd-widget-heading title-en\">Product Description</span>\n" +
                "            </div>\n" +
                "        </div>\n" +
                "        <div class=\"ssd-module content\">\n" +
                "            <div class=\"ssd-widget-text content-text\">\n" +
                intro +
                "            </div>\n" +
                "        </div>\n" +
                "        <div>\n" +
                tableBuilder.toString() +
                "        </div>\n" +
                "        <div>\n" +
                imageHtml.toString() +
                "        </div>\n" +
                "    </div>\n" +
                "</div>";
        return html;
    }

    private String buildMobileMultiSkuIntro(List<String> items) {

        if ( items==null || items.size()==0 ) {
            return "";
        }

        SkuItem skuItem = null;
        AttrTable attrTable = null;

        MYMROSkuParser skuParser = new MYMROSkuParser();

        for (String item : items) {
            System.out.println("Is Gaea: " + item);
            String url = String.format("https://www.mymro.cn/u-%s.html", item);
            String html = htmlLodService.load(url);

            skuItem = skuParser.parser(url, html);
            if ( skuItem!=null ) {
                attrTable = skuParser.attrTable(html);
                break;
            }
        }

        if ( skuItem==null ) {
            return "";
        }

        String intro = skuItem.getIntro();
        if ( StringUtils.isNotBlank(skuItem.getBrand()) ) {
            intro = StringUtils.replaceIgnoreCase(intro, skuItem.getBrand(), "");
        }
        if ( StringUtils.isNotBlank(skuItem.getBrandEn()) ) {
            intro = StringUtils.replaceIgnoreCase(intro, skuItem.getBrandEn(), "");
        }
        int height = 100;
        String[] lines = intro.split("<br>");
        if ( lines!=null && lines.length > 3  ) {
            height = 60 + lines.length*20;
        }


        StringBuilder tableBuilder = new StringBuilder();
        if ( attrTable.getHeaders()!=null && attrTable.getHeaders().size() > 0 ) {

            Set<String> codeSet = items.stream().collect(Collectors.toSet());

            tableBuilder.append("<table cellpadding=\"0\" cellspacing=\"1\" width=\"100%\" border=\"0\" class=\"Ptable param_table\">\n");

            tableBuilder.append(
                    "           <thead class=\"thead-dark\">\n" +
                            "                       <tr>\n" +
                            "                                    <th class=\"productcode\">型号</th>\n");
            for (String header : attrTable.getHeaders()) {
                tableBuilder.append("                    <th>").append(header).append("</th>\n");
            }
            tableBuilder.append(
                    "                       </tr>\n" +
                    "            </thead>\n" +
                    "            <tbody>\n");

            for (Map<String, String> record : attrTable.getDatas()) {
                String code = record.remove("订货号");
                if ( StringUtils.isBlank(code) ) {
                    continue;
                }

                if ( !codeSet.contains(code.trim()) ) {
                    continue;
                }

                String model = record.remove("制造商型号");
                tableBuilder.append("   <tr>\n" +
                        "                    <td class=\"productcode\">" + model + "</td>\n");
                for (String header : attrTable.getHeaders()) {
                    tableBuilder.append("    <td>" + record.get(header)  + "</td>\n");
                }
                tableBuilder.append("   </tr>\n");
            }
            tableBuilder.append("   </tbody>\n" +
                    "            </table>");
        }


        // 详情图片
        StringBuilder imageHtml = new StringBuilder();
        {
            if (  skuItem.getDetailPics()!=null ) {
                for (SkuItem.Pic pic : skuItem.getDetailPics()) {
                    try {
                        String vcUrl = vcPictureService.loadVCPicUrl(pic.getUrl(), "");
                        if (  StringUtils.isNotBlank(vcUrl) ) {
                            imageHtml.append(" <img src='" + vcUrl + "' />\n");
                            break;
                        }
                    } catch (Exception e) {

                    }
                }
            }
        }

        // 如果没有详情图片, 添加一张主图图片
        if ( imageHtml.length() == 0 ) {
            if (  skuItem.getProductPics()!=null ) {
                for (SkuItem.Pic pic : skuItem.getProductPics()) {
                    try {
                        String vcUrl = vcPictureService.loadProductVCPicUrl(pic.getUrl(), "");
                        if (  StringUtils.isNotBlank(vcUrl) ) {
                            imageHtml.append(" <img src='" + vcUrl + "' style=\"width:100%;\"/>\n");
                        }
                    } catch (Exception e) {

                    }
                }
            }
        }



        String html =   "<div>\n" +
                "    <style>.detail_item2 {padding:10px; }.detail_item2 th, .detail_item2 td{    transform: scale(0.6);padding:0px!important;}</style>\n" +"<div class=\"detail_item2 p_prop\" >\n" +
                "    <div>" +
                intro +
                "            </div>\n" +
                "        <div style=\"margin-top:10px;\">\n" +
                tableBuilder.toString() +
                "        </div>\n" +
                "        <div>\n" +
                imageHtml.toString() +
                "        </div>\n" +
                "</div></div>";
        return html;
    }

    /**
     * 构建单产品详情页
     * @param item
     * @return
     */
    private String buildMobileSingleSkuIntro(String item) {

        if ( item==null ) {
            return "";
        }


        MYMROSkuParser skuParser = new MYMROSkuParser();

        System.out.println("6666666: "+ item);
        String url = String.format("https://www.mymro.cn/u-%s.html", item);
        String html = htmlLodService.load(url);

        SkuItem skuItem = skuParser.parser(url, html);
        if ( skuItem==null ) {
            return "";
        }

        String intro = skuItem.getIntro();
        int height = 100;
        String[] lines = intro.split("<br>");
        if ( lines!=null && lines.length > 3  ) {
            height = 60 + lines.length*20;
        }


        StringBuilder textDetail = new StringBuilder();

        textDetail.append("<div><table cellpadding=\"0\" cellspacing=\"1\" width=\"100%\" border=\"0\" class=\"Ptable param_table\"><tbody>");
        if ( skuItem.getAttrs().size() > 0 ) {

            for (Map.Entry<String, String> entity : skuItem.getAttrs().entrySet()) {
                textDetail.append("<tr>")
                          .append("<td>").append(entity.getKey()).append(": </td>")
                          .append("<td>").append(entity.getValue()).append("</td>")
                          .append("</tr>\n");
                height += 26;
            }
//            textDetail.append("<br>\n");
        }
        textDetail.append("</tbody></table></div>");


        if ( StringUtils.isNotBlank(skuItem.getBrand()) ) {
            intro = StringUtils.replaceIgnoreCase(intro, skuItem.getBrand(), "");
        }
        if ( StringUtils.isNotBlank(skuItem.getBrandEn()) ) {
            intro = StringUtils.replaceIgnoreCase(intro, skuItem.getBrandEn(), "");
        }
        textDetail.append("<div style=\"line-height:20px;margin-top: 10px;\">").append(intro).append("</div>");

        LOG.info("9999999sSKU数量: {}", skuItem.getDetailPics().size());
        // 详情图片
        StringBuilder images = new StringBuilder();
        {
            if (  skuItem.getDetailPics()!=null ) {
                for (SkuItem.Pic pic : skuItem.getDetailPics()) {
                    try {
                        String vcUrl = vcPictureService.loadVCPicUrl(pic.getUrl(), "");
                        if (  StringUtils.isNotBlank(vcUrl) ) {
                            images.append(" <img src='" + vcUrl + "' style=\"width:100%;\"/>\n");
                            break;
                        }
                    } catch (Exception e) {

                    }
                }
            }
        }
//
        // 如果没有详情图片, 添加一张主图图片
        if ( images.length() == 0 ) {
            if (  skuItem.getProductPics()!=null ) {
                for (SkuItem.Pic pic : skuItem.getProductPics()) {
                    try {
                        String vcUrl = vcPictureService.loadProductVCPicUrl(pic.getUrl(), "");
                        if (  StringUtils.isNotBlank(vcUrl) ) {
                            images.append(" <img src='" + vcUrl + "' />\n");
                        }
                    } catch (Exception e) {

                    }
                }
            }
        }

        String result = "<div class=\"detail_item2 p_prop\" style=\"padding:10px;\">\n" +
                "    <div>" +
                textDetail.toString() +
                "        <div style=\"padding:10px;\">\n" +
                images.toString() +
                "        </div>\n" +
                "    </div>\n" +
                "</div>\n";

        return result;
    }

    private String buildPCSingleSkuIntro(String item) {

        if ( item==null ) {
            return "";
        }


        MYMROSkuParser skuParser = new MYMROSkuParser();

        String url = String.format("https://www.mymro.cn/u-%s.html", item);
        String html = htmlLodService.load(url);

        SkuItem skuItem = skuParser.parser(url, html);
        if ( skuItem==null ) {
            return "";
        }

        String intro = skuItem.getIntro();
        int height = 100;
        String[] lines = intro.split("<br>");
        if ( lines!=null && lines.length > 3  ) {
            height = 60 + lines.length*20;
        }


        StringBuilder textDetail = new StringBuilder();

        if ( skuItem.getAttrs().size() > 0 ) {

            for (Map.Entry<String, String> entity : skuItem.getAttrs().entrySet()) {
                textDetail.append("<div class=\"package-list\">\n")
                        .append("    <h3>").append(entity.getKey()).append(": </h3>\n")
                        .append("     <p>").append(entity.getValue()).append("</p>\n")
                        .append("</div>\n");
                height += 26;
            }
            textDetail.append("<br>\n");

        }

        if ( StringUtils.isNotBlank(skuItem.getBrand()) ) {
            intro = StringUtils.replaceIgnoreCase(intro, skuItem.getBrand(), "");
        }
        if ( StringUtils.isNotBlank(skuItem.getBrandEn()) ) {
            intro = StringUtils.replaceIgnoreCase(intro, skuItem.getBrandEn(), "");
        }
        textDetail.append(intro);


        // 详情图片
        StringBuilder images = new StringBuilder();
        {
            if (  skuItem.getDetailPics()!=null ) {
                for (SkuItem.Pic pic : skuItem.getDetailPics()) {
                    try {
                        String vcUrl = vcPictureService.loadVCPicUrl(pic.getUrl(), "");
                        if (  StringUtils.isNotBlank(vcUrl) ) {
                            images.append(" <img src='" + vcUrl + "' />\n");
                            break;
                        }
                    } catch (Exception e) {

                    }
                }
            }
        }
//
        // 如果没有详情图片, 添加一张主图图片
        if ( images.length() == 0 ) {
            if (  skuItem.getProductPics()!=null ) {
                for (SkuItem.Pic pic : skuItem.getProductPics()) {
                    try {
                        String vcUrl = vcPictureService.loadProductVCPicUrl(pic.getUrl(), "");
                        if (  StringUtils.isNotBlank(vcUrl) ) {
                            images.append(" <img src='" + vcUrl + "' />\n");
                        }
                    } catch (Exception e) {

                    }
                }
            }
        }

        String result = "<div>\n" +
                "    <style>.ssd-module-wrap {\n" +
                "        position: relative;\n" +
                "        margin: 0 auto;\n" +
                "        width: 750px;\n" +
                "        text-align: left;\n" +
                "        background-color: #fff\n" +
                "    }\n" +
                "\n" +
                "    .ssd-module-wrap .ssd-module, .ssd-module-wrap .ssd-module-heading {\n" +
                "        width: 750px;\n" +
                "        position: relative;\n" +
                "        overflow: hidden\n" +
                "    }\n" +
                "\n" +
                "    .ssd-module-wrap .ssd-module {\n" +
                "        background-repeat: no-repeat;\n" +
                "        background-position: left top;\n" +
                "        background-size: 100% 100%\n" +
                "    }\n" +
                "\n" +
                "    .ssd-module-wrap .ssd-module-heading {\n" +
                "        background-repeat: no-repeat;\n" +
                "        background-position: left center;\n" +
                "        background-size: 100% 100%\n" +
                "    }\n" +
                "\n" +
                "    .ssd-module-wrap .ssd-module-heading .ssd-module-heading-layout {\n" +
                "        display: inline-block\n" +
                "    }\n" +
                "\n" +
                "    .ssd-module-wrap .ssd-module-heading .ssd-widget-heading {\n" +
                "        font-style: normal;\n" +
                "        font-family: microsoft yahei;\n" +
                "        line-height: 30px;\n" +
                "        text-decoration: none;\n" +
                "        letter-spacing: 0px;\n" +
                "        font-weight: normal;\n" +
                "        color: #ffffff;\n" +
                "        background-color: transparent;\n" +
                "        display: inline-block;\n" +
                "        height: 100%\n" +
                "    }\n" +
                "\n" +
                "    .ssd-module-wrap .ssd-widget-text {\n" +
                "        position: absolute;\n" +
                "        overflow: hidden\n" +
                "    }\n" +
                "\n" +
                "    .ssd-module-wrap .ssd-widget-text {\n" +
                "        line-height: 1.5;\n" +
                "        word-break: break-all\n" +
                "    }\n" +
                "\n" +
                "    .ssd-module-wrap .ssd-widget-text span {\n" +
                "        display: block;\n" +
                "        overflow: hidden;\n" +
                "        width: 100%;\n" +
                "        height: 100%;\n" +
                "        padding: 0;\n" +
                "        margin: 0;\n" +
                "        word-break: break-all;\n" +
                "        word-wrap: break-word;\n" +
                "        white-space: normal\n" +
                "    }\n" +
                "\n" +
                "    .ssd-module-wrap .title {\n" +
                "        width: 750px;\n" +
                "        background-color: transparent;\n" +
                "        background-image: url(//img30.360buyimg.com/sku/jfs/t2467/315/1479078334/2361/4757d7d6/566010f4N01f5d17a.png);\n" +
                "        height: 30px;\n" +
                "        text-align: left\n" +
                "    }\n" +
                "\n" +
                "    .ssd-module-wrap .title-ch {\n" +
                "        margin: 0 6px 0 15px;\n" +
                "        font-size: 14px\n" +
                "    }\n" +
                "\n" +
                "    .ssd-module-wrap .title-en {\n" +
                "        margin: 0 15px 0 6px;\n" +
                "        font-size: 12px\n" +
                "    }\n" +
                "\n" +
                "    .ssd-module-wrap .content {\n" +
                "        width: 750px;\n" +
                "        background-size: 100% auto;\n" +
                "        height: " + height + "px\n" +
                "    }\n" +
                "\n" +
                "    .ssd-module-wrap .content-text {\n" +
                "        z-index: 0;\n" +
                "        color: #000000;\n" +
                "        font-weight: normal;\n" +
                "        letter-spacing: 0px;\n" +
                "        text-decoration: none;\n" +
                "        font-size: 14px;\n" +
                "        line-height: 1.5;\n" +
                "        font-style: normal;\n" +
                "        background-color: transparent;\n" +
                "        top: 16px;\n" +
                "        left: 42px;\n" +
                "        font-family: microsoft yahei;\n" +
                "        min-height: 110px\n" +
                "    }\n" +
                "\n" +
                "    .ssd-module-wrap img {\n" +
                "        margin: 10px 0 0 0;\n" +
                "        width: 750px;\n" +
                "        background-size: 100% 100%;\n" +
                "        height: auto;\n" +
                "    }\n" +
                "    .ssd-module-wrap .content-text .package-list {\n" +
                "        padding: 0;\n" +
                "        width: 700px;\n" +
                "        margin: 0px;\n" +
                "    }\n" +
                "\n" +
                "    .ssd-module-wrap .content-text .package-list h3{\n" +
                "        width: 220px;\n" +
                "        text-align: left;\n" +
                "        color: black;\n" +
                "        font-size: 14px;\n" +
                "        font-weight: bold;\n" +
                "    }\n" +
                "\n" +
                "    .ssd-module-wrap .content-text .package-list p {\n" +
                "        color: black;\n" +
                "        margin-left: 165px;\n" +
                "    }" +
                "    </style>\n" +
                "\n" +
                "    <div class=\"ssd-module-wrap\">\n" +
                "        <div class=\"ssd-module-heading title\">\n" +
                "            <div class=\"ssd-module-heading-layout\">\n" +
                "                <span class=\"ssd-widget-heading title-ch\">产品信息</span>\n" +
                "                <span class=\"ssd-widget-heading title-en\">Product Description</span>\n" +
                "            </div>\n" +
                "        </div>\n" +
                "        <div class=\"ssd-module content\">\n" +
                "            <div class=\"ssd-widget-text content-text\">\n" +
                textDetail.toString() +
                "            </div>\n" +
                "        </div>\n" +
                "        <div>\n" +
                images.toString() +
                "        </div>\n" +
                "    </div>\n" +
                "</div>\n";

        return result;
    }

    @Override
    public String buildMobileIntroHtml(List<VCShelvesItem> items) {
        if ( items==null || items.size()==0 ) {
            return "";
        }

        List<String> newItems = items.stream().map(e -> e.getSkucode() ).collect(Collectors.toList());

        if ( items.size()==1 ) {
            return buildMobileSingleSkuIntro(newItems.get(0));
        }

        return buildMobileMultiSkuIntro(newItems);
    }

    @Override
    public String buildMobileIntroHtml2(List<VCItem> items){
        if ( items==null || items.size()==0 ) {
            return "";
        }

        List<String> newItems = items.stream().map(e -> CodeEncoder.decoder(e.getItemNum()) ).collect(Collectors.toList());

        String retStr;
        if ( items.size()==1 ) {
             retStr= buildMobileSingleSkuIntro(newItems.get(0));
        }else{
            retStr = buildMobileMultiSkuIntro(newItems);
        }

        retStr = StringUtils.replaceIgnoreCase(retStr, "固安捷[\\w\\W]+公司", "帷易胜(江苏)工业品有限公司");
        return retStr;
    }

    private VCProductInfo loadVCProductInfo(String _wareId) {
        String wareId = StringUtils.trim(_wareId);
        if ( StringUtils.isBlank(wareId) ) {
            return null;
        }

        VCProductInfo vcProductInfo = vcProductInfoDao.load(wareId);
        return vcProductInfo;
    }

    public static void main(String[] args) throws Exception {

       List<VCShelvesItem> items =  SQLExecutor.executeQueryBeanList("select * from VC_SHELVES_ITEM where SKUCODE = ?", VCShelvesItem.class, "5F0187");


        System.out.println(new JDIntroServiceImpl().buildPCIntroHtml(items));

    }
}
